<?php
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
	#CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id

	+ Module  		: t_rapk View
	+ Description	: For record view
	+ Filename 		: v_t_rapk.php
 	+ creator  		: 
 	+ Created on 24/Jul/2012 10:52:52

*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
		
		
		#tblayout-win {
			font-size:12px;
			font-family:Verdana, Arial sans-serif;
		}
		#tblayout-win td{
			padding:5px;
			border:1px solid gray;
		}
		
		#main-panel td {
            padding:0px;
        }
    </style>
<script>
/* decalare KONSTANSTA */
var FAILED_SAVE="Data gagal disimpan";
var FAILED_CONNECTION="Koneksi database server gagal, hubungi Administrator";
var FAILED_VALID_FORM="Data input belum sempurna";
var FAILED_DELETE_SELECTED="Tidak ada data yang terpilih untuk dihapus";
var FAILED_UPDATE_SELECTED="Tidak ada data yang terpilih untuk diupdate";
var FAILED_DELETE="Data gagal dihapus";
var FAILED_EXCEL="Data gagal diexport ke Excel";
var FAILED_PRINT="Data gagal dicetak";
var FAILED_PERMISSION="Anda tidak mempunyai akses untuk aksi ini";
var CONFIRM_DELETE="Apakah Anda yakin menghapus rekod ini?";
var CONFIRM_MULTI_DELETE="Apakah Anda yakin menghapus rekod-rekod ini?";
var SUCCESS_SAVE="Data sukses disimpan";
var TITLE_LIST="Daftar Data";
var TITLE_FORM="Form Input/Update";
var TITLE_FORM_SEARCH="Pencarian Lanjut";
var BTN_SAVE="Simpan";
var BTN_SEARCH="Cari";
var BTN_CANCEL="Reset";
var BTN_ADD_TITLE="Tambah";
var BTN_EDIT_TITLE="Ubah";
var BTN_DELETE_TITLE="Hapus";
var BTN_SEARCH_TITLE="Pencarian";
var BTN_PRINT_TITLE="Cetak";
var BTN_EXCEL_TITLE="Export Excel";
var BTN_REFRESH_TITLE="Refresh";
var BTN_ADD_TOOLTIP="Tambah Data Baru";
var BTN_EDIT_TOOLTIP="Ubah Data";
var BTN_DELETE_TOOLTIP="Hapus Data";
var BTN_SEARCH_TOOLTIP="Pencarian Data Lanjut";
var BTN_SIMPLE_SEARCH_TOOLTIP="Pencarian Sederhana";
var BTN_PRINT_TOOLTIP="Cetak Data (html)";
var BTN_EXCEL_TOOLTIP="Export ke bentuk Excel";
var BTN_REFERSH_TOOLTIP="Refresh Data";
var INFO_REQUIRED="Wajib diisi";
var PERMISSION="RCUD";
//declare konstant
var post2db = 'CREATE';
var msg = 'created';
var pageS=15;
var div_id_field = 0;

var date_now = new Date();

/* on ready fuction */
Ext.onReady(function(){
  	Ext.QuickTips.init();	/* Initiate quick tips icon */
  	
  	Ext.util.Format.comboRenderer = function(combo){
  	    return function(value){
  	        var record = combo.findRecord(combo.valueField, value);
  	        return record ? record.get(combo.displayField) : combo.valueNotFoundText;
  	    };
  	};
  	
  	/* START DATA */
  	var negoDataStore = new Ext.data.Store({
		id: 'negoDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_negosiasi&m=get_action',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'nego_id'
		},[
			{name: 'nego_id', type: 'int', mapping: 'nego_id'},
			{name: 'branch_id', type: 'int', mapping: 'branch_id'},
			{name: 'branch_name', type: 'string', mapping: 'branch_name'},
			{name: 'project_id', type: 'int', mapping: 'project_id'},
			{name: 'project_code', type: 'string', mapping: 'project_code'},
			{name: 'project_name', type: 'string', mapping: 'project_name'},
			{name: 'job_id', type: 'int', mapping: 'job_id'},
			{name: 'job_name', type: 'string', mapping: 'job_name'},
			{name: 'nego_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'nego_date'},
			{name: 'nego_no', type: 'string', mapping: 'nego_no'},
			{name: 'komp_id', type: 'int', mapping: 'komp_id'},
			{name: 'div_name', type: 'string', mapping: 'div_name'}
		]),
		sortInfo:{field: 'branch_name', direction: "ASC"}
	});
  	negoDataStore.load({params: {start: 0, limit: pageS}});	// load DataStore
  	
  	var branchDataStore = new Ext.data.Store({
		id: 'branchDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_branch', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'branch_id'
		},[
			{name: 'branch_id', type: 'int', mapping: 'branch_id'},
			{name: 'branch_name', type: 'string', mapping: 'branch_name'},
			{name: 'branch_active', type: 'string', mapping: 'branch_active'},
			{name: 'dvo_id', type: 'int', mapping: 'dvo_id'},
			{name: 'dvo_name', type: 'string', mapping: 'dvo_name'}
		]),
		sortInfo:{field: 'branch_name', direction: "ASC"}
	});
	
  	var paymentDataStore = new Ext.data.Store({
		id: 'paymentDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_payment', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'payment_id'
		},[
			{name: 'payment_id', type: 'int', mapping: 'payment_id'},
			{name: 'payment_name', type: 'string', mapping: 'payment_name'}
		]),
		sortInfo:{field: 'payment_name', direction: "ASC"}
	});
	paymentDataStore.load();

	var projectDataStore = new Ext.data.Store({
		id: 'projectDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_project', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'project_id'
		},[
			{name: 'project_id', type: 'int', mapping: 'project_id'},
			{name: 'project_name', type: 'string', mapping: 'project_name'},
			{name: 'project_code', type: 'string', mapping: 'project_code'}
		]),
		sortInfo:{field: 'project_code', direction: "ASC"}
	});
	var tpl_projectDS = new Ext.XTemplate(
			'<tpl for="."><div class="search-item">',
            '<span><b>[{project_code}]</b><br /></span>',
            '{project_name}',
            '</div></tpl>'
	);
	
	var jobDataStore = new Ext.data.Store({
		id: 'jobDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_job_bybranchprojectBelumMenang', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'job_id'
		},[
			{name: 'job_id', type: 'int', mapping: 'job_id'},
			{name: 'job_name', type: 'string', mapping: 'job_name'},
			{name: 'div_id', type: 'string', mapping: 'div_id'},
			{name: 'div_name', type: 'string', mapping: 'div_name'},
			{name: 'rapkdet_total', type: 'float', mapping: 'rapkdet_total'}
		]),
		sortInfo:{field: 'job_name', direction: "ASC"}
	});
	
	var nego_kompDataStore = new Ext.data.Store({
		id: 'nego_kompDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_komp_byfilter', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'komp_id'
		},[
			{name: 'komp_id', type: 'int', mapping: 'komp_id'},
			{name: 'vendor_id', type: 'int', mapping: 'vendor_id'},
			{name: 'vendor_name', type: 'string', mapping: 'vendor_name'},
			{name: 'vendor_address', type: 'string', mapping: 'vendor_address'},
			{name: 'komp_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'komp_date'},
			{name: 'komp_no', type: 'string', mapping: 'komp_no'},
			{name: 'komp_total', type: 'float', mapping: 'komp_total'},
			{name: 'rapk_total', type: 'float', mapping: 'rapk_total'}
		]),
		sortInfo:{field: 'komp_id', direction: "ASC"}
	});
	
	var negodetDataStore = new Ext.data.Store({
		id: 'negodetDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_negosiasi&m=negodet_byfilter',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'negodet_id'
		},[
			{name: 'negodet_id', type: 'int', mapping: 'negodet_id'},
			{name: 'nego_rapktotal', type: 'float', mapping: 'nego_rapktotal'},
			{name: 'nego_waktu', type: 'int', mapping: 'nego_waktu'},
			{name: 'nego_waktu_satuan', type: 'string', mapping: 'nego_waktu_satuan'},
			{name: 'nego_bayar', type: 'string', mapping: 'nego_bayar'},
			{name: 'vendor_id', type: 'int', mapping: 'vendor_id'},
			{name: 'vendor_name', type: 'string', mapping: 'vendor_name'},
			{name: 'komp_id', type: 'int', mapping: 'komp_id'},
			{name: 'komp_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'komp_date'},
			{name: 'komp_no', type: 'string', mapping: 'komp_no'},
			{name: 'negodet_id', type: 'int', mapping: 'negodet_id'},
			{name: 'komp_total', type: 'float', mapping: 'komp_total'},
			{name: 'negodet_keahlian', type: 'string', mapping: 'negodet_keahlian'},
			{name: 'negodet_metode', type: 'string', mapping: 'negodet_metode'},
			{name: 'negodet_peralatan', type: 'string', mapping: 'negodet_peralatan'},
			{name: 'negodet_k3l', type: 'string', mapping: 'negodet_k3l'},
			{name: 'negodet_waktu', type: 'int', mapping: 'negodet_waktu'},
			{name: 'negodet_bayar', type: 'string', mapping: 'negodet_bayar'},
			{name: 'negodet_lulus', type: 'string', mapping: 'negodet_lulus'},
			{name: 'negodet_menang', type: 'string', mapping: 'negodet_menang'},
			{name: 'negodet_kp', type: 'string', mapping: 'negodet_kp'}
		]),
		sortInfo:{field: 'negodet_id', direction: "ASC"}
	});

	var badetDataStore = new Ext.data.Store({
		id: 'badetDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_negosiasi&m=badet_list', 
			method: 'POST'
		}),baseParams: {start: 0, limit: 15 },
			reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'badet_id'
		},[ 
			{name: 'kompdet_id', type: 'int', mapping: 'kompdet_id'},
			{name: 'kompdet_unit', type: 'int', mapping: 'kompdet_unit'},
			{name: 'kompdet_vol', type: 'int', mapping: 'kompdet_vol'},
			{name: 'kompdet_price', type: 'int', mapping: 'kompdet_price'},
			{name: 'spkdet_id', type: 'int', mapping: 'spkdet_id'},
			{name: 'm_jobdet_id', type: 'string', mapping: 'm_jobdet_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'},
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'spek_name', type: 'string', mapping: 'spkdet_spec'} // 
		])
	});

	var badet_atkompdetDataStore = new Ext.data.Store({
		id: 'badet_atkompdetDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_negosiasi&m=badet_atkompdet_list', 
			method: 'POST'
		}),
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'kompdet_id'
		},[
			{name: 'kompdet_id', type: 'int', mapping: 'kompdet_id'},
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'},
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'kompdet_vol', type: 'int', mapping: 'kompdet_vol'},
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'}
		]),
		sortInfo:{field: 'jobdet_name', direction: "ASC"}
	});
  	/* END DATA */
  	
  	
  	/* START FORM */
	var add_pemenang = function(data, index){
		
		var vendor = data[0].vendor_name;
		var pnwr_total = data[0].pnwr_total;
		
		var untung = Number(rapktotalField.getValue()) - Number(pnwr_total);
		var untung_persen = format_number(((untung/(Number(rapktotalField.getValue()))) * 100),2);
		var label_untung = "UNTUNG";
		if (untung < 0 ) {
			untung_persen = untung_persen * -1;
			untung = untung * -1;
			label_untung = "RUGI";
		}
		var html_info = "&nbsp;&nbsp;" + vendor + "&nbsp;&nbsp;&nbsp;>>> "+label_untung+": " + formatCurrency(untung) + "&nbsp;>>> " + untung_persen + "% &nbsp;";
		
		/*var pemenang_labelField = 'pemenang_labelField'+index;
   	   	pemenang_labelField = new Ext.form.Label({
	   	   	id: 'pemenang_labelField'+index, 
	        //html: data
	        html: html_info
   	   	});*/
   	   	var arr_labelField = 'arr_labelField'+index;
   	   	arr_labelField = new Ext.form.Label({
   	   	   	id: 'arr_labelField'+index,
   	   	   	html: html_info
   	   	});
		var text_div = 'Cetak SPK';
		console.log(div_id_field);
		if (div_id_field  == '503. Sub Kontraktor' ){
			text_div = 'Cetak SPK';
			Ext.getCmp('kontrakpayung_checkboxField'+index).setVisible(false);
		}else{
			if (Ext.getCmp('kontrakpayung_checkboxField'+index).getValue() == true){
				text_div = 'Cetak IPB';
			}else{
				text_div = 'Cetak PO';
			}
		}
								
   	 	var pemenang_labelField = 'pemenang_labelField'+index;
   	 	pemenang_labelField = new Ext.Panel({
   	 		id: 'pemenang_labelField'+index,
   	 		bodyStyle: 'margin-bottom: 5px;',
   	 		layout:'table',
   	 		layoutConfig: {columns: 2},
   	 		items: [new Ext.Button({
   	   	 		id: 'ba_klarifikasiBtn'+index,
   	            text: '<b>'+text_div+'</b>',
   	            minWidth: '100',
   	            handler: function(){
   	        //    	before_display_ba_window(index);
			// nanti di sini di kasih if dan juga fungsi cetak PO
   	            	display_ba_window(index,nego_idField.getValue()); //cetak spk
   	            }
   	        })
			, arr_labelField]
   	 	});
   	   	return pemenang_labelField;
   	};
   	var del_pemenang = function(data, index){
   		var pemenang_panel = Ext.getCmp('informasi_pemenangForm');
   		
   	   	var pemenang_labelField = Ext.getCmp('pemenang_labelField'+index);
   	 	pemenang_panel.remove(pemenang_labelField);
   	 	pemenang_panel.doLayout();
   	};
   	
  	var add_subkont = function(data, index){
  	  	var negodet_id = data.negodet_id;
  		var komp_id = data.komp_id;
  		var tgl = data.komp_date.format('Y-m-d');
  		var no_surat = data.komp_no;
  		var vendor_id = data.vendor_id;
  		var vendor_name = data.vendor_name;
  		var vendor_address = data.vendor_address;
  		var komp_total = data.komp_total;
		var pnwr_total_cfField = 'pnwr_total_cfField'+index;
  		pnwr_total_cfField = new Ext.form.TextField({
            id: 'pnwr_total_cfField'+index,
            hideLabel: true,
            width: 192,
            //value: formatCurrency(komp_total),
            allowNegatife : false,
    		itemCls: 'rmoney',
    		readOnly: true,
    		maskRe: /([0-9]+)$/
  		});
  		pnwr_total_cfField.setValue(formatCurrency(komp_total));

  		var pnwr_totalField = 'pnwr_totalField'+index;
  		pnwr_totalField = new Ext.form.NumberField({
            id: 'pnwr_totalField'+index,
            hideLabel: true,
            allowNegatife : false,
            hidden: true,
    		maskRe: /([0-9]+)$/
  		});
  		pnwr_totalField.setValue(komp_total);

  		var sub_name = "SUBKONT A";
  		if(index==1){
  			sub_name = "SUBKONT B";
  		}else if(index==2){
  			sub_name = "SUBKONT C";
  		}else if(index==3){
  			sub_name = "SUBKONT D";
  		}else if(index==4){
  			sub_name = "SUBKONT E";
  		}else if(index==5){
  			sub_name = "SUBKONT F";
  		}else if(index==6){
  			sub_name = "SUBKONT G";
  		}

  		var keahlian = '';
  		var metode = '';
  		var peralatan = '';
  		var k3l = '';
  		var waktu = 0;
  		var waktu_satuan = '';
  		var bayar = '';
  		var hslseleksi_luluschecked = false;
  		var hslseleksi_tidakluluschecked = false;
  		var putusan_checked = false;
		var kp_checked = false;

  		if(data.negodet_keahlian !== undefined){keahlian = data.negodet_keahlian;}
  		if(data.negodet_metode !== undefined){metode = data.negodet_metode;}
  		if(data.negodet_peralatan !== undefined){peralatan = data.negodet_peralatan;}
  		if(data.negodet_k3l !== undefined){k3l = data.negodet_k3l;}
  		if(data.negodet_waktu !== undefined){waktu = data.negodet_waktu;}
  		if(data.nego_waktu_satuan !== undefined){waktu_satuan = data.nego_waktu_satuan;}
  		if(data.negodet_bayar !== undefined){bayar = data.negodet_bayar;}
  		if(data.negodet_lulus !== undefined){
  	  		if(data.negodet_lulus == 'Y'){
  	  			hslseleksi_luluschecked = true;
  	  			hslseleksi_tidakluluschecked = false;
  	  		}else{
  	  			hslseleksi_luluschecked = false;
	  			hslseleksi_tidakluluschecked = true;
  	  		}
	  	}
  		if(data.negodet_menang !== undefined){if(data.negodet_menang == 'Y'){putusan_checked = true;}}
  		if(data.negodet_kp !== undefined){if(data.negodet_kp == 'Y'){kp_checked = true;}}
  		
		
  	  	var columns = {
        	//title: 'Column 1',
        	width: 200,
        	xtype: 'panel', 
        	border: false,
            layout:'table',
            layoutConfig: {columns:1},
            // applied to child components
            defaults: {frame:false, width: 200, height: 30, bodyStyle: 'padding:0px 0px 0px 0px; border-bottom: 1px solid gray; border-right: 1px solid gray;'},
            labelWidth: 58,
            items:[{
            	layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray; text-align: center',
                height: 29,
                items: [{
                	xtype: 'label',
                    id: 'sub_nameField'+index,
                    text: sub_name
                },{
                	xtype: 'numberfield',
                	id: 'komp_idField'+index,
                	hidden: true,
                	value: komp_id,
                	maskRe: /([0-9]+)$/
                }]
            },{
                layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray',
                items: [{
                	xtype: 'numberfield',
                	id: 'negodet_idField'+index,
                	hidden: true,
                	value: negodet_id,
                	maskRe: /([0-9]+)$/
                },{
                	xtype: 'textfield',
                    id: 'vendorField'+index,
                    hideLabel: true,
                    width: 192,
                    readOnly: true,
                    value: vendor_name
                },{
                	xtype: 'numberfield',
                	id: 'vendor_idField'+index,
                	hidden: true,
                	value: vendor_id,
                	maskRe: /([0-9]+)$/
                },{
                	xtype: 'textfield',
                    id: 'vendor_addressField'+index,
                    hidden: true,
                    width: 192,
                    readOnly: true,
                    value: vendor_address
                }]
            },{
            	layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray',
                items: [{
                    xtype: 'datefield',
                    id: 'tgl_pnwrField'+index,
                    fieldLabel: 'Tgl Pnwr',
                    hideTrigger: true,
                    width: 130,
                    readOnly: true,
                    value: tgl,
                    format: 'd/m/Y'
                }]
            },{
            	layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray',
                items: [{
                    xtype: 'textfield',
                    id: 'no_suratField'+index,
                    fieldLabel: 'No Surat',
                    width: 130,
                    readOnly: true,
                    value: no_surat
                }]
            },{
            	layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray',
                items: [pnwr_total_cfField, pnwr_totalField]
            },{
                layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray',
                items: [{
                	xtype: 'textfield',
                    id: 'ahliField'+index,
                    hideLabel: true,
                    width: 192,
                    readOnly: false,
                    value: keahlian
                }]
            },{
                layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray',
                items: [{
                	xtype: 'textfield',
                    id: 'metodeField'+index,
                    hideLabel: true,
                    width: 192,
                    readOnly: false,
                    value: metode
                }]
            },{
                layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray',
                height: 45,
                items: [{
                	xtype: 'textfield',
                    id: 'alatField'+index,
                    hideLabel: true,
                    width: 192,
                    height: 35,
                    readOnly: false,
                    value: peralatan
                }]
            },{
                layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray',
                height: 45,
                items: [{
                	xtype: 'textfield',
                    id: 'sanggupField'+index,
                    hideLabel: true,
                    width: 192,
                    height: 35,
                    readOnly: false,
                    value: k3l
                }]
            },{
                //html: 'Items 51'
                bodyStyle: 'padding-left:3px; padding-top: 3px; border: 1px solid gray;',
            	//html:'Item 34'
            	layout:'table',
    	        layoutConfig: {columns:2},
    	        // applied to child components
    	        defaults: {frame:false, height: 30, bodyStyle: 'padding:0px 0px 0px 0px;'},
    	        autoScroll: true,
    	        items:[{
    		        xtype: 'numberfield',
    		        id: 'wktselesai_numberField'+index,
    		        width: 40,
    		        height: 22,
    		        value: waktu
    	        },{
    		        xtype: 'label',
    		        id: 'wktselesai_comboField'+index,
    		        text: waktu_satuan
    	        }]
            },{
                layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray',
                items: new Ext.form.ComboBox({
					id: 'bayarField'+index,
					store: paymentDataStore,
					mode: 'remote',
					displayField:'payment_name',
					valueField: 'payment_id',
					editable: false,
					forceSelection: true,
                    width: 192,
					triggerAction: 'all',
					 hideLabel: true,
					value: bayar
				})/*[{ // disini
                	xtype: 'combo',
                    id: 'bayarField'+index,
					store: paymentDataStore,
					displayField:'payment_name',
					valueField: 'payment_id',
					editable: false,
					mode: 'remote',
                    hideLabel: true,
                    width: 192,
                    readOnly: false,
                    value: bayar
                }]
				*/
            },{
                //html: 'Items 51'
                bodyStyle: 'padding-left:3px; padding-top: 3px; border: 1px solid gray;',
            	//html:'Item 34'
            	layout:'form',
    	        //layoutConfig: {columns:2},
    	        // applied to child components
    	        defaults: {frame:false, height: 30, bodyStyle: 'padding:0px 0px 0px 0px;'},
    	        autoScroll: true,
    	        items:[{
        	        xtype: 'radiogroup',
        	        id: 'hslseleksi_radioField'+index,
        	        hideLabel: true,
        	        defaults : {xtype : 'radio' , name : 'hslseleksi_radioField'+index},
        	        items: [
        	                {
        	                    boxLabel: "LULUS",
        	                    inputValue: "Y",
        	                    checked: hslseleksi_luluschecked,
        	    				id: 'hslseleksi_lulus'+index
        	                },
        	                {
        	                    boxLabel: "TIDAK LULUS",
        	                    inputValue: "T",
        	                    checked: hslseleksi_tidakluluschecked,
        	    				id: 'hslseleksi_tidaklulus'+index,
								handler: function(node,checked){
									if (checked){
										Ext.getCmp('putusan_checkboxField'+index).setVisible(false);
										Ext.getCmp('putusan_checkboxField'+index).setValue(false);
									}else{
										Ext.getCmp('putusan_checkboxField'+index).setVisible(true);
									}
								}
        	                }
        	            ]
    	        }/*{
    		        xtype: 'checkbox',
    		        id: 'hslseleksi_checkboxField'+index,
    		        boxLabel: '',
    		        width: 40,
    		        checked: hslseleksi_checked,
            		handler: function(node,checked){
            			if (checked) {
            				Ext.getCmp('hslseleksi_labelField'+index).setText('LULUS');
            			}else{
            				Ext.getCmp('hslseleksi_labelField'+index).setText('TIDAK LULUS');
            			}
            		}
    	        },{
    		        xtype: 'label',
    		        id: 'hslseleksi_labelField'+index,
    		        width: 80,
    		        text: 'TIDAK LULUS'
    	        }*/]
            },{
                layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray',
                items: [{
                	xtype: 'radio',
                    id: 'putusan_checkboxField'+index,
                    boxLabel: '',
					name : 'putusan_checkboxField',
                    checked: putusan_checked,
					listeners : {
						'afterrender' : function(){
							
							if(Ext.getCmp('putusan_checkboxField'+index).checked){
								//Ext.getCmp('pemenang_labelField').setText('Perusahaan Pemenang &nbsp;&nbsp;&nbsp;&nbsp;UNTUNG:', true);
								var pemenang_panel = Ext.getCmp('informasi_pemenangForm');
								var data_arr = new Array();
								data_arr.push({
									'vendor_name': Ext.getCmp('vendorField'+index).getValue(), 
									'pnwr_total': Ext.getCmp('pnwr_totalField'+index).getValue()
								});
								//pemenang_panel.add(add_pemenang(Ext.getCmp('vendorField'+index).getValue(),index));
								pemenang_panel.add(add_pemenang(data_arr,index));
								pemenang_panel.doLayout();
							}else{
								var data_arr = new Array();
								data_arr.push({
									'vendor_name': Ext.getCmp('vendorField'+index).getValue(), 
									'pnwr_total': Ext.getCmp('pnwr_totalField'+index).getValue()
								});
								del_pemenang(data_arr,index);
							} 
							
							
							// poBtn & ba_klarifikasiBtn di sini 
						}
					},
                    handler: function(node,checked){
                        if(checked){
                        	//Ext.getCmp('pemenang_labelField').setText('Perusahaan Pemenang &nbsp;&nbsp;&nbsp;&nbsp;UNTUNG:', true);
                        	var pemenang_panel = Ext.getCmp('informasi_pemenangForm');
                        	var data_arr = new Array();
                        	data_arr.push({
                            	'vendor_name': Ext.getCmp('vendorField'+index).getValue(), 
                            	'pnwr_total': Ext.getCmp('pnwr_totalField'+index).getValue()
                        	});
                        	
                        	//pemenang_panel.add(add_pemenang(Ext.getCmp('vendorField'+index).getValue(),index));
                        	pemenang_panel.add(add_pemenang(data_arr,index));
                        	pemenang_panel.doLayout();
							
							if (div_id_field  == '503. Sub Kontraktor' ){
								Ext.getCmp('kontrakpayung_checkboxField'+index).setVisible(false);
							}else{
								Ext.getCmp('kontrakpayung_checkboxField'+index).setVisible(true);
							}
                        }else{
                        	var data_arr = new Array();
                        	data_arr.push({
                            	'vendor_name': Ext.getCmp('vendorField'+index).getValue(), 
                            	'pnwr_total': Ext.getCmp('pnwr_totalField'+index).getValue()
                        	});
                        	del_pemenang(data_arr,index);
							
							Ext.getCmp('kontrakpayung_checkboxField'+index).setVisible(false);
							Ext.getCmp('kontrakpayung_checkboxField'+index).setValue('false');
                        }
                    }
                }]
            },{ // payung
                layout: 'form',
                border: false,
                bodyStyle: 'padding: 3px; border: 1px solid gray',
                items: [{
                	xtype: 'checkbox',
                    id: 'kontrakpayung_checkboxField'+index,
                    boxLabel: '',
					hidden : true,
					name : 'kontrakpayung_checkboxField',
                    checked: kp_checked,
					handler : function(a,b){
						if (b){
							Ext.getCmp('ba_klarifikasiBtn'+index).setText('<b> Cetak IPB</b>');
						}else{
							Ext.getCmp('ba_klarifikasiBtn'+index).setText('<b> Cetak PO</b>');
						}
					}
                }]
            }]
  	  	};
  	  	
  	  	return columns;
   	};

   	var rapktotal_cfField = new Ext.form.TextField({
        id: 'rapktotal_cfField',
        hideLabel: true,
        width: 134,
        allowNegatife : false,
		itemCls: 'rmoney',
		readOnly: true,
		maskRe: /([0-9]+)$/
	});
	var rapktotalField = new Ext.form.NumberField({
		id: 'rapktotalField',
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	
  	var nego_gridTableLayout = new Ext.Panel({
  		id:'main-panel',
        border: false,
        layout:'table',
        layoutConfig: {columns:4},
        // applied to child components
        defaults: {frame:false, height: 30, bodyStyle: 'padding:0px 0px 0px 0px; border: 1px solid gray;'},
        items:[{
        	rowspan: 2,
        	width: 36,
            height: 150,
            bodyStyle: 'padding:5px; border: 1px solid gray; border-top: 2px solid gray; border-left: 2px solid gray; text-align: center; padding-top: 0px; font-weight: bold;',
            html:'NO'
            //html: 'Item 21,25'
        },{
        	rowspan: 2,
        	width: 150,
            height: 150,
            bodyStyle: 'padding:5px; border: 1px solid gray; border-top: 2px solid gray; text-align: center; padding-top: 0px; font-weight: bold;',
        	html:'KRITERIA'
        	//html: 'Item 22,26'
        },{
        	rowspan: 2,
        	width: 146,
            height: 150,
            bodyStyle: 'padding:5px; border: 1px solid gray; border-top: 2px solid gray; text-align: center; padding-top: 0px; font-weight: bold;',
        	html:'YANG DISYARATKAN RAPK'
        	//html: 'Item 23,27'
        },{
        	width: 670,
        	bodyStyle: 'border: 1px solid gray; border-top: 2px solid gray; border-right: 2px solid gray; text-align: center; padding-top: 5px; font-weight: bold;',
            //html: 'Items 24'
        	html: 'KEMAMPUAN YANG DIMILIKI'
        },{
        	rowspan: 12,
        	width: 670,
        	height: 480,
        	bodyStyle: 'border: 1px solid gray; border-right: 2px solid gray;',
        	//html: 'Items 28'
        	xtype: 'panel',
        	//width: 670,
        	autoScroll: true,
        	layout: 'form',
        	items: [{
        		id: 'panel_subkont',
            	layout: 'column',
            	border: false,
            	//width: 900,
            	items: []
        	}]
        },{
        	bodyStyle: 'border: 1px solid gray; border-left: 2px solid gray;',
            //html: 'Items 29'
        	html: '1.'
        },{
            //html: 'Items 30'
        	bodyStyle: 'padding:5px; border: 1px solid gray;',
        	html:'HARGA'
        },{
            //html: 'Items 31'
            bodyStyle: 'padding:3px; border: 1px solid gray;',
            layout: 'form',
            items:[rapktotal_cfField,rapktotalField]
        },{
        	bodyStyle: 'border: 1px solid gray; border-left: 2px solid gray;',
            //html: 'Items 33'
        	html: '2.'
        },{
            //html: 'Items 34'
        	bodyStyle: 'padding:5px; border: 1px solid gray;',
        	html:'KEAHLIAN PERSONIL'
        },{
            //html: 'Items 35'
            html: ''
        },{
        	bodyStyle: 'border: 1px solid gray; border-left: 2px solid gray;',
            //html: 'Items 37'
        	html: '3.'
        },{
            //html: 'Items 38'
        	bodyStyle: 'padding:5px; border: 1px solid gray;',
        	html:'METODE KERJA (**)'
        },{
            //html: 'Items 39'
        	html: ''
        },{
        	height: 45,
        	bodyStyle: 'border: 1px solid gray; border-left: 2px solid gray;',
            //html: 'Items 41'
        	html: '4.'
        },{
            //html: 'Items 42'
        	//width: 150,
        	height: 45,
        	bodyStyle: 'padding:5px; border: 1px solid gray;',
        	html:'PERALATAN YANG DIPAKAI SESUAI KETENTUAN K3L'
        },{
        	height: 45,
            //html: 'Items 43'
        	html: ''
        },{
        	height: 45,
        	bodyStyle: 'border: 1px solid gray; border-left: 2px solid gray;',
            //html: 'Items 45'
        	html: '5.'
        },{
            //html: 'Items 46'
        	//width: 150,
        	height: 45,
        	bodyStyle: 'padding:5px; border: 1px solid gray;',
        	html:'SANGGUP MEMENUHI PERSYARATAN K3L'
        },{
        	height: 45,
            //html: 'Items 47'
        	html: ''
        },{
        	bodyStyle: 'border: 1px solid gray; border-left: 2px solid gray;',
            //html: 'Items 49'
        	html: '6.'
        },{
            //html: 'Items 50'
        	bodyStyle: 'padding:5px; border: 1px solid gray;',
        	html:'WAKTU PENYELESAIAN (**)'
        },{
            //html: 'Items 51'
            bodyStyle: 'padding-left:3px; padding-top: 3px; border: 1px solid gray;',
        	//html:'Item 34'
        	layout:'table',
	        layoutConfig: {columns:2},
	        // applied to child components
	        defaults: {frame:false, height: 30, bodyStyle: 'padding:0px 0px 0px 0px;'},
	        autoScroll: true,
	        items:[{
		        xtype: 'numberfield',
		        id: 'nego_waktuField',
		        width: 40,
		        height: 22
	        },new Ext.form.Label({html : '&nbsp;&nbsp;Hari'}),{
		        xtype: 'combo',
		        id: 'nego_waktuSatuanField',
		        typeAhead: true,
		        triggerAction: 'all',
				hidden : true,
		        lazyRender:true,
		        mode: 'local',
		        store: new Ext.data.ArrayStore({
		            id: 0,
		            fields: [
		                'valueText',
		                'displayText'
		            ],
		            data: [['Hari', 'Hari'], ['Bulan', 'Bulan'], ['Tahun', 'Tahun']]
		        }),
		        valueField: 'valueText',
		        displayField: 'displayText',
		        width: 80,
		        listeners: {
		        	'select': function(){
		        		var records = nego_kompDataStore;
		          		var records_count = records.getCount();
		          		for(var i=0; i<records_count; i++){
		          			Ext.getCmp('wktselesai_comboField'+i).setText('&nbsp;&nbsp;'+this.getRawValue(), false);
		          		}
		        	}
		        }
	        }
	        ]
        },{
        	bodyStyle: 'border: 1px solid gray; border-left: 2px solid gray;',
            //html: 'Items 53'
        	html: '7.'
        },{
            //html: 'Items 54' disini
        	bodyStyle: 'padding:5px; border: 1px solid gray;',
        	html:'CARA PEMBAYARAN'
        },{
            //html: 'Items 55'
            bodyStyle: 'padding:3px; border: 1px solid gray;',
            items: new Ext.form.ComboBox({
					id: 'payment_textField',
					store: paymentDataStore,
					mode: 'remote',
					displayField:'payment_name',
					valueField: 'payment_id',
					editable: false,
					forceSelection: true,
                    width: 192,
					triggerAction: 'all',
					 hideLabel: true
				})//[{xtype: 'textfield', id: 'payment_textField', width: 134}]
        },{
        	bodyStyle: 'border: 1px solid gray; border-left: 2px solid gray;',
            //html: 'Items 57'
        	html: 'I.'
        },{
        	colspan: 2,
            bodyStyle: 'padding:5px; border: 1px solid gray;',
            //html: 'Items 58'
        	html:'HASIL SELEKSI SUBKONTRAKTOR ADALAH:'
        },{
        	rowspan: 3,
            height: 90,
            bodyStyle: 'padding:5px; border: 1px solid gray; border-left: 2px solid gray;',
            //html: 'Items 61'
            html: 'II.'
        },{
        	colspan: 2,
            bodyStyle: 'padding:5px; border: 1px solid gray;',
            //html: 'Items 62'
            html: 'KEPUTUSAN SUBKONTTRAKTOR YANG DIPILIH:'
        },{
        	colspan: 2,
            bodyStyle: 'padding:5px; border: 1px solid gray;',
			html: 'APAKAH KONTRAK PAYUNG ?'
        },{
        	colspan: 2,
            bodyStyle: 'padding:5px; border: 1px solid gray;',
            //html: 'Items 66'
            html: ''
        },{
            rowspan: 2,
            height: 90,
        	bodyStyle: 'padding:5px; border: 1px solid gray; border-left: 2px solid gray; border-bottom: 2px solid gray;',
        	html:'III.'
        },{
        	colspan: 3,
            bodyStyle: 'padding:5px; border: 1px solid gray; border-right: 2px solid gray;',
            //html: 'Items 74'
            html: 'TINJAUAN TERHADAP RAPK'
        },{
        	colspan: 3,
        	height: 60,
            bodyStyle: 'padding:5px; border: 1px solid gray; border-right: 2px solid gray; border-bottom: 2px solid gray;',
            id: 'informasi_pemenangForm',
            //html: 'Items 74'
            layout:'table',
	        layoutConfig: {columns:1},
            items: [/*{
                xtype: 'form',
                id: 'informasi_pemenangForm',
                border: false,
                items: []
            }*/]
        }]
  	});

  	
  	
  	var nego_idField = new Ext.form.NumberField({
		id: 'nego_idField',
		fieldLabel: 'Negosiasi Id ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		hidden: true,
		maskRe: /([0-9]+)$/
	});
  	var nego_branchField = new Ext.form.ComboBox({
		id: 'nego_branchField',
		fieldLabel: 'Cabang <font color=red>*</font>',
		store: branchDataStore,
		mode: 'remote',
		displayField:'branch_name',
		valueField: 'branch_id',
        editable: false,
        forceSelection: true,
        width: 250,
		pageSize: 15,
		triggerAction: 'all',
		allowBlank: false
	});
  	var nego_paymentField = new Ext.form.ComboBox({
		id: 'nego_paymentField',
		store: paymentDataStore,
		mode: 'remote',
		displayField:'payment_name',
		valueField: 'payment_id',
        editable: false,
        forceSelection: true,
        width: 250,
		pageSize: 15,
		triggerAction: 'all',
		allowBlank: false
	});
	nego_branchField.on('select', function(){
		nego_branchField.disable();
		projectDataStore.setBaseParam('branch_id', nego_branchField.getValue());
		projectDataStore.load();
	});
	var nego_dateField = new Ext.form.DateField({
		id: 'nego_dateField',
		fieldLabel: 'Tgl Seleksi <font color=red>*</font>',
		format : 'l, F d, Y',
		width: 250,
		allowBlank: false
	});
	var nego_projectField = new Ext.form.ComboBox({
		id: 'nego_projectField',
		fieldLabel: 'Kode Proyek <font color=red>*</font>',
		store: projectDataStore,
		mode: 'local',
		displayField:'project_code',
		valueField: 'project_id',
        editable: true,
        width: 250,
		pageSize: 15,
		itemSelector: 'div.search-item',
		tpl: tpl_projectDS,
		triggerAction: 'all',
		allowBlank: false
	});
	nego_projectField.on('select', function(){
		var record = nego_projectField.findRecord(nego_projectField.valueField, nego_projectField.getValue());
		//nego_projectNameField.setValue(record.get(nego_projectField.displayField));
		nego_projectNameField.setValue(record.data.project_name);
		nego_projectField.disable();
		
		jobDataStore.setBaseParam('branch_id', nego_branchField.getValue());
		jobDataStore.setBaseParam('project_id', nego_projectField.getValue());
		jobDataStore.load();
	});
	var nego_projectNameField = new Ext.form.TextField({
		id: 'nego_projectNameField',
		fieldLabel: 'Nama Proyek',
		width: 250,
		readOnly: true
	});
	var nego_jobField = new Ext.form.ComboBox({
		id: 'nego_jobField',
		fieldLabel: 'Jenis Pekerjaan <font color=red>*</font>',
		store: jobDataStore,
		mode: 'local',
		displayField:'job_name',
		valueField: 'job_id',
        editable: false,
        width: 250,
		pageSize: 15,
		triggerAction: 'all',
		allowBlank: false
	});
	nego_jobField.on('select', function(){
		var indexofds = jobDataStore.findExact('job_id', nego_jobField.getValue(), 0);
		div_id_field = jobDataStore.getAt(indexofds).data.div_name ;
		console.log(div_id_field);
		//load data komparasi
		nego_kompDataStore.setBaseParam('branch_id', nego_branchField.getValue());
		nego_kompDataStore.setBaseParam('project_id', nego_projectField.getValue());
		nego_kompDataStore.setBaseParam('job_id', nego_jobField.getValue());
		nego_kompDataStore.load({
			callback: function(opts, success, response){
				if(success){
					gen_data_komparasi();
					//rapktotal_cfField
					//Ext.getCmp('rapktotal_cfField').setValue(formatCurrency(jobDataStore.getAt(indexofds).data.rapkdet_total));
					rapktotalField.setValue(jobDataStore.getAt(indexofds).data.rapkdet_total);
					rapktotal_cfField.setValue(formatCurrency(jobDataStore.getAt(indexofds).data.rapkdet_total));
					Ext.getCmp('nego_waktuSatuanField').setValue('Hari');
					var records = nego_kompDataStore;
					var records_count = records.getCount();
					for(var i=0; i<records_count; i++){
						Ext.getCmp('wktselesai_comboField'+i).setText('&nbsp;&nbsp;Hari', false);
					}
				}
			}
		});
	});

	nego_btn_saveForm=new Ext.Button({
		text: '<b>'+BTN_SAVE+'</b>',
		handler: nego_save_form_handler,
		hidden: true
	});
	nego_printing_saveForm=new Ext.Button({
		text: '<b>Simpan dan Cetak</b>',
		handler: function(){
			nego_save_form('save_printpdf');
		}
	});
  	var nego_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		title: TITLE_FORM+' Seleksi',
		bodyStyle:'padding:5px',
		autoHeight:true,
		width: 1024,
		collapsible: true,
		frame: true,
		renderTo: 'el_nego_save_form',
		layout:'form',
		items:[{
			layout: 'column',
			border: false,
			items:[{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[nego_idField ,nego_branchField ,nego_dateField ,new  Ext.form.Label({html:'Keterangan : <font color=red>*</font>  '+INFO_REQUIRED }) ]
			},{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[nego_projectField ,nego_projectNameField ,nego_jobField]
			}]
		},nego_gridTableLayout ],
		buttons: [nego_printing_saveForm, nego_btn_saveForm
			,{
				text: '<b>'+BTN_CANCEL+'</b>',
				handler: function(){
					nego_reset_form();
				}
			}
		]
	});
  	
  //start main grid panel
	negoColumnModel = new Ext.grid.ColumnModel(
		[{
			header: 'Komp Id',
			dataIndex: 'komp_id',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Cabang',
			dataIndex: 'branch_name',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Kode Proyek',
			dataIndex: 'project_code',
			width: 150,
			sortable: false
		},
		{
			header: 'Nama Proyek',
			dataIndex: 'project_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Jenis Proyek',
			dataIndex: 'job_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Tgl Seleksi',
			dataIndex: 'nego_date',
			width: 150,
			sortable: false,
			renderer: Ext.util.Format.dateRenderer('Y-m-d'),
			editor: new Ext.form.DateField({
				format: 'l, M d, Y'
			}),
			hidden: true
		},
		{
			header: 'No.Rec',
			dataIndex: 'nego_no',
			width: 150,
			sortable: false
		}	]);

	negoColumnModel.defaultSortable= true;

    /* Button Control */
    nego_gbtn_add=new Ext.Button({
	    text: BTN_ADD_TITLE,
		tooltip: BTN_ADD_TOOLTIP,
		iconCls:'icon-adds',
		handler: nego_reset_form
    });

    nego_gbtn_update=new Ext.Button({
	    text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: nego_confirm_update
	});

    nego_gbtn_delete=new Ext.Button({
	    text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: t_nego_confirm_delete
	});
	
	//delete main grid
	function t_nego_confirm_delete(){
		// only one t_project is selected here
		if(negoListGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_DELETE, t_nego_delete);
		} else if(negoListGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_MULTI_DELETE, t_nego_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_DELETE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	function t_nego_delete(btn){
		if(btn=='yes'){

		var patt=new RegExp("D");
		if(patt.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

			var selections = negoListGrid.selModel.getSelections();
			var prez = [];
			for(var i = 0; i< negoListGrid.selModel.getCount(); i++){
				prez.push(selections[i].json.nego_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_t_negosiasi&m=get_action',
				params: { task: "DELETE", ids:  encoded_array },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							negoDataStore.reload();
							break;
						case 3:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: "Data ini sudah diproses tidak bisa dihapus",
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: FAILED_DELETE,
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});
				}
			});

			}

		}
	}
  	
  	negoListGrid = new Ext.grid.GridPanel({
		id: 'negoListGrid',
		el: 'lg_nego',
		title: TITLE_LIST,
		autoHeight: true,
		collapsible: true,
		store: negoDataStore, // DataStore
		cm: negoColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
		//plugins: expander_project_list,
	  	width: 1024,
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: negoDataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		nego_gbtn_add, '-',
		nego_gbtn_update, '-',
		nego_gbtn_delete, '-',
		new Ext.app.SearchField({
			store: negoDataStore,
			listeners:{
				specialkey: function(f,e){
					if(e.getKey() == e.ENTER){
						negoDataStore.baseParams={task:'LIST', start:0, limit:pageS};
		            }
				},
				render: function(c){
				Ext.get(this.id).set({qtitle: BTN_SIMPLE_SEARCH_TOOLTIP});
				}
			},
			width: 120
		})
		]
	});
	negoListGrid.render();

	//Start BA Klarifikasi
	var badet_kompdet_idField = new Ext.form.NumberField({
		id: 'badet_kompdet_idField',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		disabled: true,
		maskRe: /([0-9]+)$/
	});
	var badet_uraianField = new Ext.form.ComboBox({
		id: 'badet_uraianField',
		store: badet_atkompdetDataStore,
		mode: 'local',
		displayField:'jobdet_name',
		valueField: 'jobdet_id',
        editable: true,
        forceSelection: true,
		pageSize: 15,
		triggerAction: 'all'
	});
	/*badet_uraianField.on('focus', function(){
		//console.log('urain focus');
		badet_uraianField.expand();
	});*/
	badet_uraianField.on('select', function(){
		var record = badet_uraianField.findRecord(badet_uraianField.valueField, badet_uraianField.getValue());
		//komp_projectNameField.setValue(record.get(komp_projectField.displayField));
		badet_kompdet_idField.setValue(record.data.kompdet_id);
		badet_unit_idField.setValue(record.data.unit_id);
		
		badet_unit_nameField.setValue(record.data.unit_name);
		badet_volField.setValue(record.data.kompdet_vol);
	});
	var badet_unit_idField = new Ext.form.NumberField({
		id: 'badet_unit_idField',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		disabled: true,
		maskRe: /([0-9]+)$/
	});
	var badet_unit_nameField = new Ext.form.TextField({
		id: 'badet_unit_nameField',
		readOnly: true
	});
	var badet_volField = new Ext.form.NumberField({
		id: 'badet_volField',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		readOnly: true,
		maskRe: /([0-9]+)$/
	}); // kompdet_id, kompdet_unit, kompdet_vol, kompdet_price, m_jobdet_id
	var badetColumnModel = new Ext.grid.ColumnModel(
		[{
			dataIndex: 'kompdet_id',
			hidden : true
		//	renderer: Ext.util.Format.comboRenderer(badet_uraianField)
		},{
			header: 'Uraian',
			dataIndex: 'jobdet_name',
			width: 300,
			editor: new Ext.form.TextField({
				id: 'Uraianfield',
				hideLabel: true,
				readOnly : true
			})
		//	renderer: Ext.util.Format.comboRenderer(badet_uraianField)
		},
		{
			header: 'Sat',
			dataIndex: 'unit_name',
			width: 100,
			editor: new Ext.form.TextField({
				id: 'Satfield',
				readOnly : true
				})
		},
		{
			header: 'Vol',
			dataIndex: 'kompdet_vol',
			width: 100,
			align : 'right',renderer: Ext.util.Format.numberRenderer('0.000/i'),
			editor: new Ext.form.TextField({
				id: 'Volfield',
				readOnly : true
				})
				
		},
		{
			header: 'Spesifikasi',
			dataIndex: 'spek_name',
			width: 100,
			editor: new Ext.form.TextField({
				id: 'Spesifikasifield',
				readOnly : true
			})
		}]
	);
	badetColumnModel.defaultSortable= true;

	var editor_badet= new Ext.ux.grid.RowEditor({
        saveText: 'Update',
        clicksToEdit:2,
        listeners: {
        	'afteredit': function(){
        		/*var detail_total = 0;
        		
        		var detail_store = t_rapk_jobdetListEditorGrid.getStore();
        		for(var i=0;i<detail_store.getCount();i++){
            		var vol = detail_store.getAt(i).data.rapkdet_volume;
            		var hrg = detail_store.getAt(i).data.rapkdet_price;
            		if(vol !== undefined && hrg !== undefined){
            			detail_total+= (detail_store.getAt(i).data.rapkdet_volume * detail_store.getAt(i).data.rapkdet_price);
            		}
        			
        		}
        		rapk_jobdet_total_cfField.setValue(formatCurrency(detail_total));*/
        	}
        }
    });
	
	var badetListEditorGrid = new Ext.grid.EditorGridPanel({
		id: 'badetListEditorGrid',
		//el: 'fp_m_jobdet',
		title: 'Detail Data Pekerjaan',
		height: 250,
		width: '98%',
		autoScroll: true,
		store: badetDataStore, // DataStore
		colModel: badetColumnModel, // Nama-nama Columns
		enableColLock:false,
		region: 'center',
        margins: '0 5 5 5',
		plugins: [editor_badet],
		frame: true,
		//autoExpandColumn: 'uraian_jenis_merk_ukuran',
		//clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:false},
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: badetDataStore,
			displayInfo: true
		})
		/* Add Control on ToolBar */
	/*	tbar: [
		{
			text: 'Add',
			tooltip: 'Add new detail record',
			iconCls:'icon-adds',    				// this is defined in our styles.css
			handler: badet_add
		}/*, '-',{
			text: 'Delete',
			tooltip: 'Delete detail selected record',
			iconCls:'icon-delete',
			handler: m_jobdet_confirm_delete
		}
		] */
	});

	var wakil_vendor1Field = new Ext.form.TextField({
		id: 'wakil_vendor1Field',
		fieldLabel: '1',
		width: 250
	});
	var wakil_vendor2Field = new Ext.form.TextField({
		id: 'wakil_vendor2Field',
		fieldLabel: '2',
		width: 250
	});
	var wakil_vendor3Field = new Ext.form.TextField({
		id: 'wakil_vendor3Field',
		fieldLabel: '3',
		width: 250
	});

	var wakil_vendorGroup = new Ext.form.FieldSet({
		title: 'WAKIL SUBKONT',
		//autoHeight: true,
		collapsible: false,
		layout:'form',
		labelWidth: 20,
		height: 120,
		items:[wakil_vendor1Field, wakil_vendor2Field, wakil_vendor3Field]
	});

	var wakil_owner1Field = new Ext.form.TextField({
		id: 'wakil_owner1Field',
		fieldLabel: '1',
		width: 250
	});
	var wakil_owner2Field = new Ext.form.TextField({
		id: 'wakil_owner2Field',
		fieldLabel: '2',
		width: 250
	});
	
	var wakil_ownerGroup = new Ext.form.FieldSet({
		title: 'WAKIL PT. PP',
		//autoHeight: true,
		collapsible: false,
		layout:'form',
		labelWidth: 20,
		height: 120,
		items:[wakil_owner1Field, wakil_owner2Field]
	});

	var ba_t_nego_idField = new Ext.form.NumberField({
		id: 'ba_t_nego_idField',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		width: 250,
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	var ba_t_komp_idField = new Ext.form.NumberField({
		id: 'ba_t_komp_idField',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		width: 250,
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	var indexField = new Ext.form.NumberField({
		id: 'indexField',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		width: 250,
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	
	var ba_noField = new Ext.form.Label({
   	   	id: 'ba_noField', 
        //html: data
        html: 'NO. 96/IX/PP-555521/2012'
	});

	var ba_negodateField = new Ext.form.DateField({
		id: 'ba_negodateField',
		fieldLabel: 'Tgl Nego',
		format : 'l, F d, Y',
		readOnly: true,
		hideTrigger: true,
		width: 250
	});

	var ba_dateField = new Ext.form.DateField({
		id: 'ba_dateField',
		fieldLabel: 'Tgl BA',
		format : 'l, F d, Y',
		allowBlank: false,
		width: 250
	});
	
	/// spk disini ///
	
	var spk_idField = new Ext.form.TextField({
		id: 'spk_idField',
		fieldLabel: 'Id SPK',
		width: 250,
		hidden : true,
		readOnly : true
	});
	
	var spk_dateField = new Ext.form.DateField({
		id: 'spk_dateField',
		fieldLabel: 'Tanggal',
		format : 'l, F d, Y',
		allowBlank: false,
		width: 250
	});	
	
	var spk_noField = new Ext.form.TextField({
		id: 'spk_noField',
		fieldLabel: 'Nomor',
		width: 250
	});

	var ba_subkontField = new Ext.form.TextArea({
		id: 'ba_subkontField',
		fieldLabel: 'Nama Subkont',
		readOnly: true,
		width: 250
	});
	
	var top_spekField = new Ext.form.TextArea({
		id: 'top_spekField',
		fieldLabel: 'Spesifikasi',
		readOnly : true,
		width: 250
	});

	var jenis_spekField = new Ext.form.ComboBox({
		id: 'jenis_spekField',
		fieldLabel: 'Jenis Spesifikasi',
		store : ['Umum','Per detil'],
		mode: 'local',
		triggerAction: 'all',
		editable: false,
        width: 192,
		listeners : {
			'select' : function(a,b,c){
				if (c){
					top_spekField.setValue('');
					top_spekField.setReadOnly(true);
					Ext.getCmp('Spesifikasifield').setReadOnly(false);
				}else{
					top_spekField.setReadOnly(false);
					Ext.getCmp('Spesifikasifield').setReadOnly(true);
				}
			}
		}
	})
				
	var ba_jobField = new Ext.form.TextField({
		id: 'ba_jobField',
		fieldLabel: 'Pekerjaan',
		readOnly: true,
		width: 250
	});

	var ba_rapktotal_cfField = new Ext.form.TextField({
        id: 'ba_rapktotal_cfField',
        fieldLabel: 'Penawaran',
        width: 250,
        allowNegatife : false,
		itemCls: 'rmoney',
		readOnly: true,
		maskRe: /([0-9]+)$/
	});
	var ba_rapktotalField = new Ext.form.NumberField({
		id: 'ba_rapktotalField',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		width: 250,
		hidden: true,
		maskRe: /([0-9]+)$/
	});

	var ba_negototal_cfField = new Ext.form.TextField({
        id: 'ba_negototal_cfField',
        fieldLabel: 'Negosiasi',
        width: 250,
        allowNegatife : false,
		itemCls: 'rmoney',
		readOnly: true,
		maskRe: /([0-9]+)$/
	});
	var ba_negototalField = new Ext.form.NumberField({
		id: 'ba_negototalField',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		width: 250,
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	
	var ba_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		layout:'form',
		bodyStyle:'padding:5px',
		autoHeight:true,
		frame: true,
		width: 750,
		items: [
			{
			layout: 'column',
			border: false,
			items:[{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [spk_idField,spk_dateField, jenis_spekField]
			
			},{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [spk_noField, top_spekField]
			}]
		},  badetListEditorGrid,indexField,
	/*	{
			layout: 'column',
			border: false,
			items:[{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[wakil_vendorGroup]
			},{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [wakil_ownerGroup]
			}]
		} */],
		buttons: [{
				text: 'Simpan',
				handler: ba_save_form
			},{
				text: 'Cetak',
				handler: spk_cetak
			},{
				text: 'Edit',
				handler: spk_editopen
			},{
				text: 'Keluar',
				handler: function(){
					baWindow.hide();
				}
			}
		]
	});
	
	var baWindow = new Ext.Window({
		title: 'CETAK',
		closable:true,
		closeAction: 'hide',
		autoWidth: true,
		autoHeight: true,
		plain:true,
		layout: 'fit',
		x: 0,
		y: 0,
		modal: true,
		renderTo: 'elwindow_ba',
		items: ba_saveForm
	});
	
	spkEditHtmlEditor = new Ext.ux.TinyMCE({
		fieldLabel: 'Konten',
		hideLabel: false,
		name : 'spkEditHtmlEditor',
		tinymceSettings: {
			mode : "textareas",
			theme : "advanced",
			plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,visualblocks",
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,code,|,insertdate,preview,|,forecolor,backcolor",
			theme_advanced_buttons3 : "tablecontrols,|",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "none",
			theme_advanced_resizing : false,
			theme_advanced_source_editor_height : 300
		},
		width: "98%",
		height: "350",
		value: ""
	});
	
	var spkEditForm = new Ext.FormPanel({
		labelAlign: 'left',
		layout:'form',
		bodyStyle:'padding:5px',
		autoHeight:true,
		frame: true,
		width: 750,
		items: spkEditHtmlEditor,
		buttons: [{
			text: 'Simpan',
			handler: spkEditCetakSave
		}]
	});
	
	var spkEditWindow = new Ext.Window({
		title: 'EDIT',
		closable:true,
		closeAction: 'hide',
		autoWidth: true,
		autoHeight: true,
		plain:true,
		layout: 'fit',
		x: 0,
		y: 0,
		modal: true,
		renderTo: 'elwindow_editspk',
		items: spkEditForm
	});
	
	//End BA Klarifikasi
  	/* END FORM */
  	
  	
  	/* START FUNCTION */
  	//generate vendor yang telah didaftarkan di fase Komparasi
  	function gen_data_komparasi(){
  		var records = nego_kompDataStore;
  		var records_count = records.getCount();
  		var set_width = records_count * 200;
  		var panel_subkont = Ext.getCmp('panel_subkont');
  	  	panel_subkont.setWidth(set_width);

  	  	panel_subkont.removeAll();
  	  	
  	  	for(var i=0; i<records_count; i++){
  	  		panel_subkont.add(add_subkont(records.getAt(i).data, i));
  	  	}
  	  	panel_subkont.doLayout();
  	}
	/*
  	function checkbox_event(i){
			// ini saya ambil dari handler checkbox menang
		if(Ext.getCmp('putusan_checkboxField'+i).checked){
			//Ext.getCmp('pemenang_labelField').setText('Perusahaan Pemenang &nbsp;&nbsp;&nbsp;&nbsp;UNTUNG:', true);
			var pemenang_panel = Ext.getCmp('informasi_pemenangForm');
			var data_arr = new Array();
			data_arr.push({
				'vendor_name': Ext.getCmp('vendorField'+i).getValue(), 
				'pnwr_total': Ext.getCmp('pnwr_totalField'+i).getValue()
			});
					
			//pemenang_panel.add(add_pemenang(Ext.getCmp('vendorField'+i).getValue(),i));
			pemenang_panel.add(add_pemenang(data_arr,i));
			pemenang_panel.doLayout();
		}else{
			var data_arr = new Array();
			data_arr.push({
				'vendor_name': Ext.getCmp('vendorField'+i).getValue(), 
				'pnwr_total': Ext.getCmp('pnwr_totalField'+i).getValue()
			});
			del_pemenang(data_arr,i);
		} 
	} */
			
  	function gen_data_negosiasi(){
  		var records = negodetDataStore;
  		var records_count = records.getCount();
  		var set_width = records_count * 200;
  		var panel_subkont = Ext.getCmp('panel_subkont');
  	  	panel_subkont.setWidth(set_width);

  	  	panel_subkont.removeAll();
  	  	
  	  	for(var i=0; i<records_count; i++){
  	  		panel_subkont.add(add_subkont(records.getAt(i).data, i));
	//		Ext.getCmp('putusan_checkboxField'+i).click();
	//		Ext.getCmp('putusan_checkboxField'+i);
	//		setTimeout(  'checkbox_event(i)' , 1000);
  	  	}
  	  	panel_subkont.doLayout();
  	}

  	function is_nego_form_valid(){
  	  	return (nego_branchField.isValid() && nego_projectField.isValid() && nego_jobField.isValid() && nego_dateField.isValid());
  	}

  	function nego_save_form_handler(){
  		nego_save_form();
  	}
  	
  	function nego_save_form(optional){
		if (typeof optional == "undefined") {
  	  	    optional = "nego_save";
  	  	}

  	  	if(is_nego_form_valid()){
  	  		//mencari data subkont dengan index = x, untuk disimpan berdasarkan keputusan yang dipilih
  	  		//1. Jumlah subkont yang ikut Negosiasi
  	  		//2. Looping dan diambil datanya yang Checkbox Keputusan terpilih
  	  		var nego_id_field = 0;
  	  		var branch_id_field = 0;
  	  		var project_id_field = 0;
  	  		var job_id_field = 0;
  	  		var nego_date_field = null;
  	  		var nego_harga_field = 0;
  	  		var nego_waktu_field = '';
  	  		var nego_waktu_satuan_field = '';
  	  		var nego_bayar_field = '';

  	  		if(nego_idField.getValue() !== null && nego_idField.getValue() !== ""){nego_id_field = nego_idField.getValue();}
  	  		if(nego_branchField.getValue() !== null){branch_id_field = nego_branchField.getValue();}
  	  		if(nego_projectField.getValue() !== null){project_id_field = nego_projectField.getValue();}
  	  		if(nego_jobField.getValue() !== null){job_id_field = nego_jobField.getValue();}
  	  		if(nego_dateField.getValue() !== null && nego_dateField.getValue() !== ''){nego_date_field = nego_dateField.getValue().format('Y-m-d');}
  	  		if(rapktotalField.getValue() !== null){nego_harga_field = rapktotalField.getValue();}
  	  		if(Ext.getCmp('nego_waktuField').getValue() !== null && Ext.getCmp('nego_waktuField').getValue() !== ''){nego_waktu_field = Ext.getCmp('nego_waktuField').getValue();}
  	  		if(Ext.getCmp('nego_waktuSatuanField').getValue() !== null && Ext.getCmp('nego_waktuSatuanField').getValue() !== ''){nego_waktu_satuan_field = Ext.getCmp('nego_waktuSatuanField').getValue();}
  	  		if(Ext.getCmp('payment_textField').getValue() !== null && Ext.getCmp('payment_textField').getValue() !== ''){nego_bayar_field = Ext.getCmp('payment_textField').getValue();}

  	  		var negodet_id_field = [];
  	  		var t_komp_id_field = [];
  	  		var negodet_harga_field = [];
  	  		var negodet_keahlian_field = [];
  	  		var negodet_metode_field = [];
  	  		var negodet_peralatan_field = [];
  	  		var negodet_k3l_field = [];
  	  		var negodet_waktu_field = [];
  	  		var negodet_bayar_field = [];
  	  		var negodet_lulus_field = [];
  	  		var negodet_menang_field = [];
  	  		var negodet_kp_field = [];
  	  		
  	  		var records = nego_kompDataStore;
  	  		var records_count = records.getCount();
  	  		if(records_count == 0){
  	  	  		records = negodetDataStore;
  	  	  		records_count = records.getCount();}{
  	  		}
  	  		for(var i=0; i<records_count; i++){
  	  			negodet_id_field.push(Ext.getCmp('negodet_idField'+i).getValue());
  	  			t_komp_id_field.push(Ext.getCmp('komp_idField'+i).getValue());
  	  			negodet_harga_field.push(Ext.getCmp('pnwr_totalField'+i).getValue());
  	  			negodet_keahlian_field.push(Ext.getCmp('ahliField'+i).getValue());
  	  			negodet_metode_field.push(Ext.getCmp('metodeField'+i).getValue());
  	  			negodet_peralatan_field.push(Ext.getCmp('alatField'+i).getValue());
  	  			negodet_k3l_field.push(Ext.getCmp('sanggupField'+i).getValue());
  	  			negodet_waktu_field.push(Ext.getCmp('wktselesai_numberField'+i).getValue());
  	  			negodet_bayar_field.push(Ext.getCmp('bayarField'+i).getValue());
				
  	  			if(Ext.getCmp('hslseleksi_radioField'+i).getValue()!== null){
  	  				negodet_lulus_field.push(Ext.getCmp('hslseleksi_radioField'+i).items.get(0).getGroupValue());
  	  			}
  	  			/*if(Ext.getCmp('hslseleksi_checkboxField'+i).getValue() == true){
  	  				negodet_lulus_field.push('Y');
  	  			}else{
  	  				negodet_lulus_field.push('T');
  	  			}*/
  	  			if(Ext.getCmp('putusan_checkboxField'+i).getValue() == true){
  	  				negodet_menang_field.push('Y');
  	  			}else{
  	  				negodet_menang_field.push('T');
  	  			}
				
  	  			if(Ext.getCmp('kontrakpayung_checkboxField'+i).getValue() == true){
  	  				negodet_kp_field.push('Y');
  	  			}else{
  	  				negodet_kp_field.push('T');
  	  			}
  	  	  			
  	  	  	}
  	  	  	
  	  		var encoded_array_negodet_id = Ext.encode(negodet_id_field);
  	  		var encoded_array_t_komp_id = Ext.encode(t_komp_id_field);
  	  		var encoded_array_negodet_harga = Ext.encode(negodet_harga_field);
  	  		var encoded_array_negodet_keahlian = Ext.encode(negodet_keahlian_field);
  	  		var encoded_array_negodet_metode = Ext.encode(negodet_metode_field);
  	  		var encoded_array_negodet_peralatan = Ext.encode(negodet_peralatan_field);
  	  		var encoded_array_negodet_k3l = Ext.encode(negodet_k3l_field);
  	  		var encoded_array_negodet_waktu = Ext.encode(negodet_waktu_field);
  	  		var encoded_array_negodet_bayar = Ext.encode(negodet_bayar_field);
  	  		var encoded_array_negodet_lulus = Ext.encode(negodet_lulus_field);
  	  		var encoded_array_negodet_menang = Ext.encode(negodet_menang_field);
  	  		var encoded_array_negodet_kp = Ext.encode(negodet_kp_field);
  	  		
  	  		Ext.Ajax.request({
  				waitMsg: 'Please wait...',
  				url: 'index.php?c=c_t_negosiasi&m=get_action',
  				params: {
  	  				nego_id: nego_id_field,
  					branch_id	: branch_id_field,
  					project_id	: project_id_field,
  					job_id	: job_id_field,
  					nego_date: nego_date_field,
  					nego_harga: nego_harga_field,
  			  		nego_waktu: nego_waktu_field,
  			  		nego_waktu_satuan: nego_waktu_satuan_field,
  			  		nego_bayar: nego_bayar_field,
  					
  					//data detail jenis pekerjaan
  					negodet_id: encoded_array_negodet_id,
  					t_komp_id: encoded_array_t_komp_id,
  					negodet_harga: encoded_array_negodet_harga,
  					negodet_keahlian: encoded_array_negodet_keahlian,
  					negodet_metode: encoded_array_negodet_metode,
  					negodet_peralatan: encoded_array_negodet_peralatan,
  					negodet_k3l: encoded_array_negodet_k3l,
  					negodet_waktu: encoded_array_negodet_waktu,
  					negodet_bayar: encoded_array_negodet_bayar,
  					negodet_lulus: encoded_array_negodet_lulus,
  					negodet_menang: encoded_array_negodet_menang,
					negodet_kp: encoded_array_negodet_kp,
  					task: post2db
  				},
  				success: function(response){
  					var result=eval(response.responseText);
  					if(result > 0){
  						if(optional=='nego_save'){
  							Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
							nego_reset_form();
  						}else if(optional=='save_printpdf'){
							Ext.Ajax.request({
								waitMsg: 'Please wait...',
								url: 'index.php?c=c_t_negosiasi&m=print_pdf_negosiasi',
								params: {
									negosiasi_id : result
								},
								success: function(response){
									win = window.open('./print/seleksi.doc', '_blank');
								},
								failure: function(response){
									Ext.MessageBox.show({
										   title: 'Error',
										   msg: FAILED_CONNECTION,
										   buttons: Ext.MessageBox.OK,
										   animEl: 'database',
										   icon: Ext.MessageBox.ERROR
									});
								}
							});
							nego_reset_form();
						}else{
  							display_ba_window(optional, result);
  						}
						//Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
						negoDataStore.reload();
						//nego_reset_form();
  					}else{
  						Ext.MessageBox.show({
						   	title: 'Warning',
						   	msg: FAILED_SAVE,
						   	buttons: Ext.MessageBox.OK,
						   	animEl: 'save',
						   	icon: Ext.MessageBox.WARNING
						});
  					}
  				},
  				failure: function(response){
  					Ext.MessageBox.show({
  						   title: 'Error',
  						   msg: FAILED_CONNECTION,
  						   buttons: Ext.MessageBox.OK,
  						   animEl: 'database',
  						   icon: Ext.MessageBox.ERROR
  					});
  				}
  			});
  	  	} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: 'Form anda belum lengkap',
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
  		
  	}
  	
  	//reset cuform
  	function nego_reset_form(){
	
  	  		Ext.Ajax.request({
  				waitMsg: 'Please wait...',
  				url: 'index.php?c=c_t_negosiasi&m=t_negosiasi_delete_temp',
  				params: {
  					secure : '1',
  				},
  				failure: function(response){
  					Ext.MessageBox.show({
  						   title: 'Error',
  						   msg: FAILED_CONNECTION,
  						   buttons: Ext.MessageBox.OK,
  						   animEl: 'database',
  						   icon: Ext.MessageBox.ERROR
  					});
  				}
  			});
			
  		post2db = 'CREATE';
		nego_branchField.enable();
  		nego_idField.reset();
  		nego_idField.setValue(null);
  		nego_branchField.reset();
  		nego_branchField.setValue(null);
  		//nego_dateField.setValue(date_now);
  		nego_dateField.reset();
  		nego_dateField.setValue(null);
		nego_projectField.enable();
  		nego_projectField.reset();
  		nego_projectField.setValue(null);
  		nego_projectNameField.reset();
  		nego_projectNameField.setValue(null);
  		nego_jobField.reset();
  		nego_jobField.setValue(null);
  		rapktotal_cfField.reset();
  		rapktotal_cfField.setValue(null);
  		rapktotalField.reset();
  		rapktotalField.setValue(null);
		Ext.getCmp('nego_waktuField').reset();
		Ext.getCmp('nego_waktuSatuanField').reset();
		Ext.getCmp('payment_textField').reset();
  		
  		var pemenang_panel = Ext.getCmp('informasi_pemenangForm');
   	 	pemenang_panel.removeAll();
   	 	pemenang_panel.doLayout();
   	 	
   	 	var subkont_panel = Ext.getCmp('panel_subkont');
   	 	subkont_panel.removeAll();
   	 	subkont_panel.doLayout();
  	}
  	
  	function nego_set_form(){
		div_id_field = negoListGrid.getSelectionModel().getSelected().get('div_name');
  		nego_idField.setValue(negoListGrid.getSelectionModel().getSelected().get('nego_id'));
  		nego_branchField.setValue(negoListGrid.getSelectionModel().getSelected().get('branch_name'));
  		nego_dateField.setValue(negoListGrid.getSelectionModel().getSelected().get('nego_date'));
  		nego_projectField.setValue(negoListGrid.getSelectionModel().getSelected().get('project_code'));
  		nego_projectNameField.setValue(negoListGrid.getSelectionModel().getSelected().get('project_name'));
  		nego_jobField.setValue(negoListGrid.getSelectionModel().getSelected().get('job_name'));
		
		//generate subkont by db.t_negodet
		negodetDataStore.setBaseParam('branch_id', negoListGrid.getSelectionModel().getSelected().get('branch_id'));
		negodetDataStore.setBaseParam('project_id', negoListGrid.getSelectionModel().getSelected().get('project_id'));
		negodetDataStore.setBaseParam('job_id', negoListGrid.getSelectionModel().getSelected().get('job_id'));
		negodetDataStore.load({
			callback: function(opts, success, response){
				if(success){
					
					rapktotalField.setValue(negodetDataStore.getAt(0).data.nego_rapktotal);
					rapktotal_cfField.setValue(formatCurrency(negodetDataStore.getAt(0).data.nego_rapktotal));
					Ext.getCmp('nego_waktuField').setValue(negodetDataStore.getAt(0).data.nego_waktu);
					Ext.getCmp('nego_waktuSatuanField').setValue(negodetDataStore.getAt(0).data.nego_waktu_satuan);
					Ext.getCmp('payment_textField').setValue(negodetDataStore.getAt(0).data.nego_bayar);
					
					
					gen_data_negosiasi();
				}
			}
		});
  	}
  	
  	function nego_confirm_update(){
  		/* only one record is selected here */
		nego_reset_form();
		if(negoListGrid.selModel.getCount() == 1) {
			post2db='UPDATE';
			msg='updated';
			nego_set_form();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_UPDATE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
  	}

  	function display_ba_window(index, t_nego_id){
		if(!baWindow.isVisible()){
			ba_t_komp_idField.setValue(Ext.getCmp('komp_idField'+index).getValue());
			//set ba_saveForm
			spk_dateField.reset();
			spk_noField.reset();
			top_spekField.reset();
			jenis_spekField.reset();
		/*	ba_dateField.reset();
			wakil_vendor1Field.reset();
			wakil_vendor2Field.reset();
			wakil_vendor3Field.reset();
			wakil_owner1Field.reset();
			wakil_owner2Field.reset();
			*/
		indexField.setValue(index);
			
			Ext.Ajax.request({
  				waitMsg: 'Please wait...',
  				url: 'index.php?c=c_t_negosiasi&m=spk_list',
  				params: {
  					t_nego_id : t_nego_id,
  					t_komp_id : Ext.getCmp('komp_idField'+index).getValue(),
					
  				},
  				success: function(response){
  					var result=eval(response.responseText);
  					if (result.total != 0 ){
						var dt = Date.parseDate(result.results[0].spk_date, "Y-m-d H:i:s");
						spk_idField.setValue(result.results[0].spk_id);
						spk_dateField.setValue(dt);
						spk_noField.setValue(result.results[0].spk_no);
						top_spekField.setValue(result.results[0].spk_spec);
						if (result.results[0].spk_spec != ''){	
							jenis_spekField.setValue('Umum');
						}else{
							jenis_spekField.setValue('Per detil');
						}
					}
  				},
  				failure: function(response){
  					Ext.MessageBox.show({
  						   title: 'Error',
  						   msg: FAILED_CONNECTION,
  						   buttons: Ext.MessageBox.OK,
  						   animEl: 'database',
  						   icon: Ext.MessageBox.ERROR
  					});
  				}
  			});
			/*
			ba_negodateField.setValue(nego_dateField.getValue());
			ba_subkontField.setValue(Ext.getCmp('vendorField'+index).getValue() + '\n' + Ext.getCmp('vendor_addressField'+index).getValue());
			if(/^\d+$/.test(nego_jobField.getValue())){
				var record_combojob = nego_jobField.findRecord(nego_jobField.valueField, nego_jobField.getValue());
				ba_jobField.setValue(record_combojob.get(nego_jobField.displayField));
			}else{
				ba_jobField.setValue(nego_jobField.getValue());
			}
			ba_rapktotal_cfField.setValue(formatCurrency(rapktotalField.getValue()));
			ba_rapktotalField.setValue(rapktotalField.getValue());

			ba_negototal_cfField.setValue(formatCurrency(Ext.getCmp('pnwr_totalField'+index).getValue()));
			ba_negototalField.setValue(Ext.getCmp('pnwr_totalField'+index).getValue());

			badet_atkompdetDataStore.setBaseParam('t_komp_id', Ext.getCmp('komp_idField'+index).getValue());
			badet_atkompdetDataStore.load();  */
			ba_t_nego_idField.setValue(t_nego_id);
			badetDataStore.removeAll(); 
			baWindow.show(); 
			badetDataStore.setBaseParam('t_komp_id', Ext.getCmp('komp_idField'+index).getValue());
			badetDataStore.setBaseParam('t_nego_id', t_nego_id );
			badetDataStore.load();
		/*	badetDataStore.removeAll(); 
			badetDataStore.setBaseParam('t_komp_id', Ext.getCmp('komp_idField'+index).getValue());
			badetDataStore.setBaseParam('t_nego_id', t_nego_id );
			*/
		} else {
			baWindow.toFront();
		}
	}

  	function badet_add(){
		var edit_badet= new badetListEditorGrid.store.recordType({
			badet_id: 0,
			kompdet_id: 0,
			jobdet_id: '',
			unit_id: 0,
			unit_name: '',
			badet_vol: 0
		});
		editor_badet.stopEditing();
		badetDataStore.insert(0, edit_badet);
		//badetListEditorGrid.getView().refresh();
		badetListEditorGrid.getSelectionModel().selectRow(0);
		editor_badet.startEditing(0);

		badet_uraianField.focus(true, 100);
	}

  	function before_display_ba_window(index_ba){
  		nego_save_form(index_ba);
  	}

  	function is_ba_form_valid(){
  	  	return (spk_dateField.isValid() && spk_noField.isValid() );
  	}
	function spkEditCetakSave(){
		spk_id = spk_idField.getValue();
		spk_cetak= spkEditHtmlEditor.getValue();
		Ext.Ajax.request({
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_t_negosiasi&m=spkSaveCetak',
			params: {
				spk_id : spk_id,
				spk_cetak : spk_cetak
			},
			success: function(response){
				if (eval(response.responseText) == 1){
					Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
					spkEditWindow.hide();
				}else{
					Ext.MessageBox.show({
					   title: 'Warning',
					   msg: 'Data gagal dicetak!',
					   buttons: Ext.MessageBox.OK,
					   animEl: 'save',
					   icon: Ext.MessageBox.WARNING
					});
				}
			},
			failure: function(response){
				Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
				});
			}
		});
	}
	function spk_editopen(){
		spk_id = spk_idField.getValue();
		if (spk_id == '' || spk_id == 0){
			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: 'Simpan terlebih dahulu sebelum melakukan edit cetak!',
			   buttons: Ext.MessageBox.OK,
			   animEl: 'sistem',
			   icon: Ext.MessageBox.WARNING
			});
		}else{
			spkEditWindow.show();
			
			Ext.Ajax.request({
				waitMsg: 'Please wait...',
				url: 'index.php?c=c_t_negosiasi&m=getSpkCetak',
				params: {
					spk_id : spk_id
					
				},
				success: function(response){
					var result=response.responseText;
					spkEditHtmlEditor.setValue(result);
				},
				failure: function(response){
					Ext.MessageBox.show({
						   title: 'Error',
						   msg: FAILED_CONNECTION,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'database',
						   icon: Ext.MessageBox.ERROR
					});
				}
			});
		}
	}
	function spk_cetak(){
		spk_id = spk_idField.getValue();
		if (spk_id == '' || spk_id == 0){
			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: 'Simpan terlebih dahulu sebelum melakukan cetak!',
			   buttons: Ext.MessageBox.OK,
			   animEl: 'sistem',
			   icon: Ext.MessageBox.WARNING
			});
		}else{
			
			Ext.Ajax.request({
				waitMsg: 'Please wait...',
				url: 'index.php?c=c_t_negosiasi&m=print_pdf_baspk',
				params: {
					spk_id : spk_id
				},
				success: function(response){
					if (eval(response.responseText) == 1){
						win = window.open('./print/cetak.doc', '_blank');
					}else{
						Ext.MessageBox.show({
						   title: 'Warning',
						   msg: 'Data gagal dicetak!',
						   buttons: Ext.MessageBox.OK,
						   animEl: 'save',
						   icon: Ext.MessageBox.WARNING
						});
					}
				},
				failure: function(response){
					Ext.MessageBox.show({
						   title: 'Error',
						   msg: FAILED_CONNECTION,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'database',
						   icon: Ext.MessageBox.ERROR
					});
				}
			});
		}
	}
	
  	function ba_save_form(){
  		//mencari data subkont dengan index = x, untuk disimpan berdasarkan keputusan yang dipilih
  		//1. Jumlah subkont yang ikut Negosiasi
  		//2. Looping dan diambil datanya yang Checkbox Keputusan terpilih
  		if(is_ba_form_valid()){
  			var ba_t_nego_id_field = ba_t_nego_idField.getValue();
  	  		var spk_date_field = null;
  	  		var spk_no_field = null;
			var index = indexField.getValue();
			var wktselesai_numberField = Ext.getCmp('wktselesai_numberField'+index);
			var wktselesai_comboField = Ext.getCmp('wktselesai_comboField'+index);
			var bayarField = Ext.getCmp('bayarField'+index);

			var wktselesai_number_Field = wktselesai_numberField.getValue();
		//	var wktselesai_combo_Field = wktselesai_comboField.text;
			var bayar_Field = bayarField.getRawValue();

  /*
  	  		var ba_vendor1_field = "";
  	  		var ba_vendor2_field = "";
  	  		var ba_vendor3_field = "";
  	  		var ba_pp1_field = "";
  	  		var ba_pp2_field = "";
  	  		var ba_date_field = null;

  	  		if(wakil_vendor1Field.getValue() !== null && wakil_vendor1Field.getValue() != ""){ba_vendor1_field = wakil_vendor1Field.getValue();}
  	  		if(wakil_vendor2Field.getValue() !== null && wakil_vendor2Field.getValue() != ""){ba_vendor2_field = wakil_vendor2Field.getValue();}
  	  		if(wakil_vendor3Field.getValue() !== null && wakil_vendor3Field.getValue() != ""){ba_vendor3_field = wakil_vendor3Field.getValue();}
  	  		if(wakil_owner1Field.getValue() !== null && wakil_owner1Field.getValue() != ""){ba_pp1_field = wakil_owner1Field.getValue();}
  	  		if(wakil_owner2Field.getValue() !== null && wakil_owner2Field.getValue() != ""){ba_pp2_field = wakil_owner2Field.getValue();}
  	  		if(ba_dateField.getValue() !== null && ba_dateField.getValue() != ""){ba_date_field = ba_dateField.getValue().format('Y-m-d');}
*/
			if(spk_dateField.getValue() !== null && spk_dateField.getValue() != ""){spk_date_field = spk_dateField.getValue().format('Y-m-d');}
			if(spk_noField.getValue() !== null && spk_noField.getValue() != ""){spk_no_field = spk_noField.getValue();}
		
			var spkdet_id_grid = [];
			var komdet_id_grid = [];
  	  		var spek_grid = [];
  	  		var spek_field = null;
  	  		var spekjenis_field = null;
			 
 // 	  		var badet_vol_field = [];
  //	  		var badet_unit_field = [];
  	  		spek_field = top_spekField.getValue();
			spekjenis_field = jenis_spekField.getValue();
			var ba_t_komp_id_field = ba_t_komp_idField.getValue();
			
  	  		var records = badetListEditorGrid.getStore();
  	  		var records_count = records.getCount();
  	  		for(var i=0; i<records_count; i++){
  			/*	if(badetListEditorGrid.getStore().getAt(i).data.jobdet_id!==undefined
  						&& badetListEditorGrid.getStore().getAt(i).data.jobdet_id!==''
  							&& badetListEditorGrid.getStore().getAt(i).data.jobdet_id!==0){ */
  					komdet_id_grid.push(badetListEditorGrid.getStore().getAt(i).data.kompdet_id);
					if ((badetListEditorGrid.getStore().getAt(i).data.spkdet_id) == null ){
						spkdet_id_grid.push('0');
					}else{
						spkdet_id_grid.push(badetListEditorGrid.getStore().getAt(i).data.spkdet_id);
					}
  					spek_grid.push(badetListEditorGrid.getStore().getAt(i).data.spek_name);
  		//		}
  	  	  			
  	  	  	}
			
  	  		var encoded_array_t_spkdet_id= Ext.encode(spkdet_id_grid);
  	  		var encoded_array_t_kompdet_id= Ext.encode(komdet_id_grid);
  	  		var encoded_array_spek_grid = Ext.encode(spek_grid);
			jenisdoc = Ext.getCmp('ba_klarifikasiBtn'+index).getText();
  	   		Ext.Ajax.request({
  				waitMsg: 'Please wait...',
  				url: 'index.php?c=c_t_negosiasi&m=spk_cu',
  				params: {
  					t_nego_id		: ba_t_nego_id_field,
  					t_komp_id		: ba_t_komp_id_field,
  					spk_date		: spk_date_field,
					spk_no			: spk_no_field,
					spek_field		: spek_field,
					jenis			: spekjenis_field,
					spkdet_id		: encoded_array_t_spkdet_id,
					spek_grid		: encoded_array_spek_grid,
					waktu_no		: wktselesai_number_Field,
  					t_kompdet_id	: encoded_array_t_kompdet_id,
					bayar			: bayar_Field,
					jobdet_grid 	: encoded_array_t_kompdet_id,
					jenisdoc		: jenisdoc
  				},
  				success: function(response){
  					var result=eval(response.responseText);

  						if(result != 0){	
							Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
  							baWindow.hide(); 
							display_ba_window(index,ba_t_nego_id_field);
						}
  				},
  				failure: function(response){
  					Ext.MessageBox.show({
  						   title: 'Error',
  						   msg: FAILED_CONNECTION,
  						   buttons: Ext.MessageBox.OK,
  						   animEl: 'database',
  						   icon: Ext.MessageBox.ERROR
  					});
  				}
  			}); 
  		} else {
 			Ext.MessageBox.show({
 				title: 'Warning',
 				msg: 'Form anda belum lengkap',
 				buttons: Ext.MessageBox.OK,
 				animEl: 'save',
 				icon: Ext.MessageBox.WARNING
 			});
 		} 
  		
  	}
  	/* END FUNCTION */

	/* START CONTROL PERMISSION */
	var pattr=new RegExp("R");
	var pattc=new RegExp("C");
	var pattu=new RegExp("U");
	var pattd=new RegExp("D");

	/*if(pattc.test(PERMISSION)==false){
		t_nego_gbtn_add.setVisible(false);
	}else{
		t_nego_gbtn_add.setVisible(true);
	}

	if(pattu.test(PERMISSION)==false){
		t_nego_gbtn_update.setVisible(false);
	}else{
		t_nego_gbtn_update.setVisible(true);
	}

	if(pattd.test(PERMISSION)==false){
		t_nego_gbtn_delete.setVisible(false);
	}else{
		t_nego_gbtn_delete.setVisible(true);
	}

	if(pattc.test(PERMISSION)==false && pattu.test(PERMISSION)==false){
		t_nego_btn_Save.setVisible(false);
	}else{
		t_nego_btn_Save.setVisible(true);
	}*/
	/* END CONTROL PERMISSION */
	
});
</script>
<body style: 'background: url(assets/images/desktop.jpg)'>
<div>
	<div class="col">
		<div id="el_nego_save_form"></div>
		<div>&nbsp;</div>
		<div id="lg_nego"></div>
		<div id="elwindow_ba"></div>
		<div id="elwindow_editspk"></div>
    </div>
</div>
</body>
</html>